package com.haifeng.asms.api.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * <p>
 *  Swagger配置类(只用于开发环境dev)
 * </p>
 * @Author: Haifeng
 * @Date: 2020-06-20
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
@Profile("dev")
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("ASMS系统接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.haifeng.asms.api.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        String name = "Haifeng";
        String url = "";
        String email = "haifeng_personal@aliyun.com";
        return new ApiInfoBuilder()
                .title("ASMS系统接口")
                .description("ASMS系统接口")
                .termsOfServiceUrl("")
                .contact(new Contact(name,url,email))
                .version("1.0")
                .build();
    }
}
